package com.songcha.module_mine.ui.adapter

import android.widget.ImageView
import android.widget.TextView
import androidx.databinding.ViewDataBinding
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.songcha.library_business.util.MajiaBaoUtil
import com.songcha.library_common.helper.ViewHelper
import com.songcha.library_common.util.GlideUtil
import com.songcha.library_common.util.StringUtil
import com.songcha.module_mine.R
import com.songcha.module_mine.databinding.MineItemBrowseHistoryBinding
import com.songcha.module_mine.structs.BrowseHistoryItem

class BrowseHistoryAdapter(list:MutableList<BrowseHistoryItem>):BaseQuickAdapter<BrowseHistoryItem,BaseViewHolder>(
    R.layout.mine_item_browse_history,list) {

    init {
        addChildClickViewIds(R.id.mine_btn_read)
    }

    override fun convert(holder: BaseViewHolder, item: BrowseHistoryItem) {
        val tvBookName = holder.getView<TextView>(R.id.mine_tv_book_name)
        val tvAuthor = holder.getView<TextView>(R.id.mine_tv_author)
        val tvDesc = holder.getView<TextView>(R.id.mine_tv_desc)
        val ivThumb = holder.getView<ImageView>(R.id.mine_iv_thumb)
        val tvProgress = holder.getView<TextView>(R.id.mine_tv_progress)
        val btnRead = holder.getView<TextView>(R.id.mine_btn_read)
        val tvProgressValue = holder.getView<TextView>(R.id.mine_tv_progress_value)

        tvBookName.text=item.bookName
        tvAuthor.text=item.author
        tvDesc.text=item.desc

        GlideUtil.loadNetImage(ivThumb,item.thumb)

        if(item.progress>0f){
            if(item.progress>=100f){
                tvProgress.text="已读完"
                tvProgressValue.text=""
                btnRead.text="继续阅读"
            }else{
                tvProgress.text="读到"
                tvProgressValue.text="${StringUtil.float2PlainString(item.progress)}%"
                btnRead.text="继续阅读"
            }
        }else{
            tvProgress.text="未读"
            tvProgressValue.text=""
            btnRead.text="开始阅读"
        }
    }

}